home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / filesearch.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-12  |  3.9 KB  |  123 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #ifndef _FILESEARCH_H
  8. #define _FILESEARCH_H
  9.  
  10. #include "scribusapi.h"
  11. #include "deferredtask.h"
  12. #include <QStringList>
  13. #include <QStack>
  14. #include <QDir>
  15.  
  16. class QTimer;
  17.  
  18. /*! \brief A class to do a depth-first search for a file in a directory tree
  19. efficiently and safely (I hope). The class is fire and forget,
  20. letting you get on with other things and take action when you're informed
  21. that the search is complete.
  22. A FileSearch is single use.
  23. */
  24. class SCRIBUS_API FileSearch : public DeferredTask
  25. {
  26.     Q_OBJECT
  27.  
  28. public:
  29.     /*! \brief Construct a new FileSearch object to search for the specified filename.
  30.     \param parent Parent object (where it will be displayed)
  31.     \param fileName should be a basename without path. Once you've created the
  32.     FileSearch, connect yourself to its searchComplete(int) signal then
  33.     start() it and return to the event loop.
  34.     \param searchBase If searchBase is not specified,
  35.     a search of the user's home directory is done. The caller is expected to
  36.     ensure that the search base exists.
  37.     \param depthLimit is -1 for no limit, otherwise number of levels deep to search.
  38.     The base dir is level 0.
  39.     \param caseSensitive it will search case INSENSITIVE filenames if false.
  40.     \warning It's useless to set caseSensitive on MS Windows! This will be set to
  41.     false on windows automatically because Windows are case insensitive already.
  42.     */
  43.     FileSearch(QObject* parent, const QString & fileName, const QString & searchBase = QString::null, int depthLimit = -1, bool caseSensitive=true);
  44.  
  45.     ~FileSearch();
  46.  
  47. public slots:
  48.     //! \brief  Begin searching.
  49.     virtual void start();
  50.  
  51.     /*! \brief Return a list of files matched. Note that it is safe to call this
  52.     while the search is still running, or after it has failed.
  53.     */
  54.     const QStringList & matchingFiles() const;
  55.  
  56.     //! \brief  Return the number of files found so far.
  57.     int foundCount() const;
  58.  
  59.     //! \brief  Return the name we're searching for
  60.     const QString & fileName() const;
  61.  
  62.     /*! \brief Return a const reference to the QDir we're using to
  63.     track our progress. This lets the caller get the dirname,
  64.     absolute dirname, etc.
  65.     */
  66.     const QDir & currentDir() const;
  67.  
  68. signals:
  69.     /*! \brief Emitted when the search has finished.
  70.     \param paths is list of paths matched,
  71.     \param filename is filename searched for.
  72.     Remember you can simply discard one or both params.
  73.     */
  74.     void searchComplete(const QStringList& paths, const QString& filename);
  75.  
  76. protected slots:
  77.     virtual void next();
  78.  
  79. protected:
  80.     /*! \brief Push a list of subdirs in the current directory onto m_tree, and
  81.     put an iterator pointing to the first subdir on top of m_iter. */
  82.     void pushStack();
  83.  
  84.     /*! \brief Scans the current directory (where QDir is set to) and adds its contents
  85.     to the list of matched files. */
  86.     void addCurrentDirFiles();
  87.  
  88.     //! \brief Case sensitive flag
  89.     bool m_caseSensitive;
  90.  
  91.     //! \brief  Where the search starts from
  92.     QString m_searchBase;
  93.  
  94.     //! \brief  What the filename we're looking for is
  95.     QString m_fileName;
  96.  
  97.     //! \brief  The list of files matched in the search
  98.     QStringList m_matchingFiles;
  99.  
  100.     /*! \brief This stack holds a list of directories on the tree, from the base
  101.     to the level we're currently searching. We use iterators into the values
  102.     of this stack to keep the search position.
  103.     */
  104.     QStack<QStringList> m_tree;
  105.  
  106.     /*! \brief A matching stack of iterators into the lists in m_tree. We use this stack
  107.     to iterate directory by directory as we search.
  108.     */
  109.     QStack<QStringList::const_iterator> m_iter;
  110.  
  111.     /*! \brief A QDir set to the current directory, used for listing files and
  112.     directories. */
  113.     QDir m_dir;
  114.  
  115.     //! \brief Conveniently keep track of how deeply we've recursed.
  116.     int m_depth;
  117.  
  118.     //! \brief Maximum depth to search to
  119.     int m_maxdepth;
  120. };
  121.  
  122. #endif
  123.